# import os
# import sys
# import json
# import django

# def dump_data():
#     try:
#         # 设置Django环境
#         os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lending_index.settings')
#         django.setup()
        
#         # 导入Django的management命令
#         from django.core.management import call_command
        
#         # 设置输出文件路径
#         output_file = 'query/fixtures/initial_data.json'
        
#         # 确保输出目录存在
#         os.makedirs(os.path.dirname(output_file), exist_ok=True)
        
#         try:
#             # 直接执行dumpdata命令，使用UTF-8编码导出数据
#             print('开始导出数据...')
#             with open(output_file, 'w', encoding='utf-8') as f:
#                 call_command(
#                     'dumpdata',
#                     'query',
#                     'auth',
#                     '--indent', '4',
#                     stdout=f
#                 )
#             print(f'数据已成功导出到 {output_file}')
            
#         except Exception as dump_error:
#             print(f'执行dumpdata命令时发生错误:')
#             print(f'错误类型: {type(dump_error).__name__}')
#             print(f'错误信息: {str(dump_error)}')
#             raise dump_error
            
#     except Exception as e:
#         print(f'导出数据时发生错误:')
#         print(f'错误类型: {type(e).__name__}')
#         print(f'错误信息: {str(e)}')
#         sys.exit(1)

# if __name__ == '__main__':
#     dump_data()